/*
 * Copyright 2014 Christian Hildebrandt
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package de.sisoft.timera.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;

/**
 *
 * @author Christian Hildebrandt
 */
@NamedQueries({
	@NamedQuery(name = "Employee.findAll", query = "SELECT e FROM Employee e"),
	@NamedQuery(name = "Employee.findEmployeeById", query = "SELECT e FROM Employee e WHERE e.id=:id"),
	@NamedQuery(name = "Employee.findEmployeeByUsername", query = "SELECT e FROM Employee e WHERE e.username LIKE :username") })
@Entity
public class Employee implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Enumerated(EnumType.STRING)
    private Salutation salutation;

    private String firstName;
    private String lastName;
    private String email;
    private String phoneNumber;

    @Column(unique = true)
    private String username;

    private String password;

    @Enumerated(EnumType.STRING)
    private Role role;

    @Temporal(javax.persistence.TemporalType.DATE)
    private Date birthday;

    @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    private Address address;

    @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "employee")
    private List<Project> associatedProjects;

    private String avatarImage;

    public Employee() {
	address = new Address();
	associatedProjects = new ArrayList<>();
    }

    public boolean hasRole(final Role role) {
	return this.role == role;
    }

    public Salutation getSalutation() {
	return salutation;
    }

    public void setSalutation(final Salutation salutation) {
	this.salutation = salutation;
    }

    public Long getId() {
	return id;
    }

    public void setId(final Long id) {
	this.id = id;
    }

    public String getFirstName() {
	return firstName;
    }

    public void setFirstName(final String firstName) {
	this.firstName = firstName;
    }

    public String getLastName() {
	return lastName;
    }

    public void setLastName(final String lastName) {
	this.lastName = lastName;
    }

    public String getEmail() {
	return email;
    }

    public void setEmail(final String email) {
	this.email = email;
    }

    public String getPhoneNumber() {
	return phoneNumber;
    }

    public void setPhoneNumber(final String phoneNumber) {
	this.phoneNumber = phoneNumber;
    }

    public Date getBirthday() {
	return birthday;
    }

    public void setBirthday(final Date birthday) {
	this.birthday = birthday;
    }

    public Address getAddress() {
	return address;
    }

    public void setAddress(final Address address) {
	this.address = address;
    }

    public String getUsername() {
	return username;
    }

    public void setUsername(final String username) {
	this.username = username;
    }

    public String getPassword() {
	return password;
    }

    public void setPassword(final String password) {
	this.password = password;
    }

    public Role getRole() {
	return role;
    }

    public void setRole(final Role role) {
	this.role = role;
    }

    public List<Project> getAssociatedProjects() {
	return associatedProjects;
    }

    public void setAssociatedProjects(final List<Project> associatedProjects) {
	this.associatedProjects = associatedProjects;
    }

    public String getAvatarImage() {
	return avatarImage;
    }

    public void setAvatarImage(final String avatarImage) {
	this.avatarImage = avatarImage;
    }

}
